package com.xulinhao.edu.controller.front;/**
 * @author xulinhao
 * @create 2021-09-04 22:38
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xulinhao.commonutils.R;
import com.xulinhao.edu.entity.Course;
import com.xulinhao.edu.entity.Teacher;
import com.xulinhao.edu.service.CourseService;
import com.xulinhao.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author xlh
 * @packagename: com.xulinhao.edu.controller.front
 * @classname: IndexFrontController
 * @Description:
 * @Date 2021/9/4
 */
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    //查询前8条热门课程,查询前4条名师
    @GetMapping("index")
    public R index(){
        //查询前8条热门课程
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<Course> eduList = courseService.list(wrapper);

        //查询前4条名师
        QueryWrapper<Teacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 4");
        List<Teacher> teacherList = teacherService.list(wrapper1);
        return R.ok().data("eduList", eduList).data("teacherList",teacherList);
    }
}
